package com.tianzehua.netty.httpexample;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 *  channel初始化器
 * @auther: tianzehua
 * @date: 2019/03/09 10:59
 * @company: ©2018版权所有 中科浩鼎科技股份有限公司
 */
public class TestServerInitializer  extends ChannelInitializer<SocketChannel> {


    @Override
    protected void initChannel(SocketChannel ch) {
        /* 连接被创建后，channel会调用该初始化方法进行回调，该方法会被调用 */

        /* 一个管道中会有许多个 channelHarder，相当于一个一个的拦截器，每个拦截器处理不同的业务 */
        ChannelPipeline pipeline = ch.pipeline();
        /*  A combination of {@link HttpRequestDecoder} and {@link HttpResponseEncoder}
         *  which enables easier server side HTTP implementation.
         *  HttpServerCodec 是一个HttpRequestDecoder和HttpResponseEncoder 的集合，简化了HTTP 请求的信息
         *  HttpRequestDecoder HTTP请求的解码，HttpResponseEncoder HTTP相应的解码
          *  */
        pipeline.addLast("httpServerCodec",new HttpServerCodec());
        pipeline.addLast("testHttpServerHandler",new TestHttpServerHandler());
    }
}
